package com.ketangpai.admin.mapper;

import com.ketangpai.admin.entity.StuWork;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface StuWorkMapper {
    // 使用 XML 配置的方法
    List<StuWork> getStudentWorks(@Param("workId") Integer workId,
                                  @Param("status") Integer status,
                                  @Param("studentName") String studentName);

    // StuWorkMapper.java
    @Select("SELECT sw.*, u.no, u.name, w.content as work_content " +
            "FROM stu_work sw " +
            "LEFT JOIN user u ON sw.user_id = u.id " +
            "LEFT JOIN work w ON sw.work_id = w.id " +
            "WHERE sw.id = #{id}")
    @ResultMap("StuWorkWithUserAndWorkMap")
    StuWork getStudentWorkDetail(@Param("id") Integer id);



    @Select("SELECT * FROM stu_work WHERE work_id = #{workId}")
    List<StuWork> getStudentWorksByWorkId(Integer workId);

    @Select("SELECT * FROM stu_work WHERE work_id = #{workId} AND status = #{status}")
    List<StuWork> getStudentWorksByStatus(@Param("workId") Integer workId, @Param("status") Integer status);

    @Update("UPDATE stu_work SET score = #{score}, message = #{message}, status = 2, " +
            "check_time = NOW(), check_count = check_count + 1 WHERE id = #{id}")
    int updateWorkGrade(@Param("id") Integer id, @Param("score") String score, @Param("message") String message);

    @Update("UPDATE stu_work SET expedite_count = expedite_count + 1 WHERE id = #{id}")
    int updateExpediteCount(Integer id);

    @Select("SELECT COUNT(*) FROM stu_work WHERE work_id = #{workId} AND status = #{status}")
    int countByStatus(@Param("workId") Integer workId, @Param("status") Integer status);
    @Update("UPDATE stu_work SET status = #{status} WHERE id = #{id}")
    int updateWorkStatus(@Param("id") Integer id, @Param("status") Integer status);
}
